<?php
include ("conn.php");
$skey = $_POST['skey'];
$mode = $_POST['mode'];
$pid = $_POST['pid'];
if($mode=="2"){
	$coid = $_POST['coid'];
}
//验证skey是否存在
$sql="SELECT * FROM user WHERE thirdSession='".$skey."'";
$result = $conn->query($sql);
if ($result->num_rows == 0) {exit('{"code":450}');}
$row = $result->fetch_assoc();
$uid = $row['id'];
//计算被点赞对象的id
if($mode=="1"){
	$objId=$pid;
}
else if($mode=="2"){
	$objId="[".$pid.",".$coid."]";
}
//检查这个skey对应的uid是否已经给这个对象点过赞
include ("findLikeNum.php");
$sql="SELECT * FROM likeList WHERE uid=".$uid." AND objId='".$objId."'";
$result = $conn->query($sql);
if ($result->num_rows == 1) {
	//改变对应赞数量
	setLikeNum($uid,$objId,$mode,-1);
	//点了就给他删掉 
	$sql="DELETE FROM likeList WHERE uid=".$uid." AND objId='".$objId."'";
	$result = $conn->query($sql);
	//改变对应赞数量
	exit('{"code":451}');
}
//增加一条点赞记录
setLikeNum($uid,$objId,$mode,1);
$sql="INSERT INTO likeList (uid, mode,objId) VALUES (".$uid.",".$mode.",'".$objId."')";
$result = $conn->query($sql);
//返回点赞成功信息
echo '{"code":452}';
?>